<?php

require_once ($cfgPaths['lib'].'cms/cmsPostProcessor.o.inc.php');

class cmsPostProcessor_txt extends cmsPostProcessor
{
  function cmsPostProcessor_txt ($conf)
  {
    parent::cmsPostProcessor($conf);
  }
  
  function blanks ($num)
  {
    $str = '';
    for ($i=0;$i<$num;$i++)
      $str .= ' ';
    return $str;
  }
  
  function processField ($str)
  {
    while (preg_match('|<div style="margin-left: (\d+)px;">|si',$str,$matches))
      $str = preg_replace('|<div style="margin-left: '.$matches[1].'px;">|i',$this->blanks($matches[1]/10),$str);

    $str = strip_tags(
            preg_replace('/<br ?\/?>/i',"\n",
            preg_replace('|<p.*?>(.*?)</p>|si','\\1'."\n\n",
            preg_replace('/(?<!<\/p>)\s*?<\/?(ol|ul)>/ims',"\n",
            preg_replace('/(<\/(ol|ul)>\s*<(ol|ul)>|<\/(ol|ul)>)/mis',"\n",
            preg_replace('/[\n\r]+/','',
            preg_replace('|<strong>(.*?)(<br>)?</strong>|si',$this->conf['bold'][0].'\\1'.$this->conf['bold'][1].'\\2',
            preg_replace('|<span style="font-weight: bold;">(.*?)</span>|si',$this->conf['bold'][0].'\\1'.$this->conf['bold'][1],
            preg_replace('|<span style="font-style: italic;">(.*?)</span>|si',$this->conf['italic'][0].'\\1'.$this->conf['italic'][1],
            preg_replace('|<em>(.*?)(<br>)?</em>|si',$this->conf['italic'][0].'\\1'.$this->conf['italic'][1].'\\2',
            preg_replace('|<span style="text-decoration: underline;">(.*?)</span>|si',$this->conf['underline'][0].'\\1'.$this->conf['underline'][1],
            preg_replace('|<u>(.*?)(<br>)?</u>|si',$this->conf['underline'][0].'\\1'.$this->conf['underline'][1].'\\2',
            preg_replace('|<span style="text-decoration: line-through;">(.*?)</span>|si',$this->conf['line-through'][0].'\\1'.$this->conf['line-through'][1],
            preg_replace('|<strike>(.*?)(<br>)?</strike>|si',$this->conf['line-through'][0].'\\1'.$this->conf['line-through'][1].'\\2',
            preg_replace('|<sub>(.*?)(<br>)?</sub>|si',$this->conf['subscript'][0].'\\1'.$this->conf['subscript'][1].'\\2',
            preg_replace('|<sup>(.*?)(<br>)?</sup>|si',$this->conf['superscript'][0].'\\1'.$this->conf['superscript'][1].'\\2',
            preg_replace('/\s*<li>/i',$this->conf['listelement'][0],
            preg_replace('/(<br>\s*)?<\/li>/ism','<br>',
            $str
      ))))))))))))))))));
    
    return $str;
  }
    
}


?>